﻿/***********************************************************
Copyright © 2015 Howyoung.
************************************************************
You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty.
************************************************************
您可以对所收受的本程序源代码，无论以何种媒介，复制与发布其完
整的复制物，然而您必须以显著及适当的方式在每一份复制物上发布
适当的著作权标示及无担保声明。
***********************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace MinecraftSavesBackup
{
    public partial class Options : Form
    {
        Main Main;

        public Options(Main pMain)
        {
            InitializeComponent();
            Main = pMain;
        }

        private void UpdateColor()
        {
            try
            {
                //更新选择的颜色
                switch (Convert.ToString(Properties.Settings.Default.BackColor))
                {
                    case "Color [DodgerBlue]":
                        backColorDodgerBlueLabel.Text = "√";
                        backColorTomatoLabel.Text = "";
                        backColorSpringGreenLabel.Text = "";
                        backColorBlueVioletLabel.Text = "";
                        backColorTurquoiseLabel.Text = "";
                        backColorOtherLabel.Text = "";
                        break;
                    case "Color [Tomato]":
                        backColorDodgerBlueLabel.Text = "";
                        backColorTomatoLabel.Text = "√";
                        backColorSpringGreenLabel.Text = "";
                        backColorBlueVioletLabel.Text = "";
                        backColorTurquoiseLabel.Text = "";
                        backColorOtherLabel.Text = "";
                        break;
                    case "Color [SpringGreen]":
                        backColorDodgerBlueLabel.Text = "";
                        backColorTomatoLabel.Text = "";
                        backColorSpringGreenLabel.Text = "√";
                        backColorBlueVioletLabel.Text = "";
                        backColorTurquoiseLabel.Text = "";
                        backColorOtherLabel.Text = "";
                        break;
                    case "Color [BlueViolet]":
                        backColorDodgerBlueLabel.Text = "";
                        backColorTomatoLabel.Text = "";
                        backColorSpringGreenLabel.Text = "";
                        backColorBlueVioletLabel.Text = "√";
                        backColorTurquoiseLabel.Text = "";
                        backColorOtherLabel.Text = "";
                        break;
                    case "Color [Turquoise]":
                        backColorDodgerBlueLabel.Text = "";
                        backColorTomatoLabel.Text = "";
                        backColorSpringGreenLabel.Text = "";
                        backColorBlueVioletLabel.Text = "";
                        backColorTurquoiseLabel.Text = "√";
                        backColorOtherLabel.Text = "";
                        break;
                    default:
                        backColorDodgerBlueLabel.Text = "";
                        backColorTomatoLabel.Text = "";
                        backColorSpringGreenLabel.Text = "";
                        backColorBlueVioletLabel.Text = "";
                        backColorTurquoiseLabel.Text = "";
                        backColorOtherLabel.Text = "√";
                        backColorOtherLabel.BackColor = Properties.Settings.Default.BackColor;
                        backColorOtherLabel.Image = null;
                        int r, g, b;
                        r = Properties.Settings.Default.BackColor.R;
                        g = Properties.Settings.Default.BackColor.G;
                        b = Properties.Settings.Default.BackColor.B;
                        if (r + g + b > 255 * 3 / 2)
                        {
                            r = r - 100;
                            g = g - 100;
                            b = b - 100;
                            if (r < 0) r = 0;
                            if (g < 0) g = 0;
                            if (b < 0) b = 0;
                        }
                        else
                        {
                            r = r + 100;
                            g = g + 100;
                            b = b + 100;
                            if (r > 255) r = 255;
                            if (g > 255) g = 255;
                            if (b > 255) b = 255;
                        }
                        backColorOtherLabel.ForeColor = Color.FromArgb(r, g, b);
                        break;
                }
                if (Properties.Settings.Default.ForeColor == Color.White)
                {
                    foreColorWhiteLabel.Text = "√";
                    foreColorBlackLabel.Text = "";
                }
                else
                {
                    foreColorWhiteLabel.Text = "";
                    foreColorBlackLabel.Text = "√";
                }
                //更新主界面颜色
                if (Properties.Settings.Default.ForeColor == Color.White)
                {
                    Main.percentLabel.ForeColor = Color.White;
                    Main.stateLabel.ForeColor = Color.White;
                    Main.startLabel.ForeColor = Color.White;
                    Main.settingsLabel.ForeColor = Color.White;
                    Main.backupLabel.ForeColor = Color.White;
                    Main.viewLabel.ForeColor = Color.White;
                    Main.helpLabel.ForeColor = Color.White;
                    Main.aboutLabel.ForeColor = Color.White;
                    Main.startPictureBox.Image = Properties.Resources.startGameWhite;
                    Main.settingsPictureBox.Image = Properties.Resources.settingsWhite;
                    Main.backupPictureBox.Image = Properties.Resources.backupWhite;
                    Main.viewPictureBox.Image = Properties.Resources.viewBackupWhite;
                    Main.helpPictureBox.Image = Properties.Resources.helpWhite;
                    Main.aboutPictureBox.Image = Properties.Resources.aboutWhite;
                }
                else
                {
                    Main.percentLabel.ForeColor = Color.Black;
                    Main.stateLabel.ForeColor = Color.Black;
                    Main.startLabel.ForeColor = Color.Black;
                    Main.settingsLabel.ForeColor = Color.Black;
                    Main.backupLabel.ForeColor = Color.Black;
                    Main.viewLabel.ForeColor = Color.Black;
                    Main.helpLabel.ForeColor = Color.Black;
                    Main.aboutLabel.ForeColor = Color.Black;
                    Main.startPictureBox.Image = Properties.Resources.startGameBlack;
                    Main.settingsPictureBox.Image = Properties.Resources.settingsBlack;
                    Main.backupPictureBox.Image = Properties.Resources.backupBlack;
                    Main.viewPictureBox.Image = Properties.Resources.viewBackupBlack;
                    Main.helpPictureBox.Image = Properties.Resources.helpBlack;
                    Main.aboutPictureBox.Image = Properties.Resources.aboutBlack;
                }
                Main.statePanel.BackColor = Properties.Settings.Default.BackColor;
                Main.startPanel.BackColor = Properties.Settings.Default.BackColor;
                Main.settingsPanel.BackColor = Properties.Settings.Default.BackColor;
                Main.backupPanel.BackColor = Properties.Settings.Default.BackColor;
                Main.viewPanel.BackColor = Properties.Settings.Default.BackColor;
                Main.helpPanel.BackColor = Properties.Settings.Default.BackColor;
                Main.aboutPanel.BackColor = Properties.Settings.Default.BackColor;
            }
            catch (Exception ex)
            {
                HandlingErrors.Record(ex);
            }
        }

        private void Options_Shown(object sender, EventArgs e)
        {
            try
            {
                //加载存档地址
                savesAddressTextBox.Text = Properties.Settings.Default.SaveAddress;
                //加载要备份的存档
                savesListBox.Items.Clear();
                foreach (string saves in Properties.Settings.Default.BackupDirectoryAddress)
                {
                    savesListBox.Items.Add(saves.Replace(Properties.Settings.Default.SaveAddress, null));
                }
                //加载全部存档
                savesCheckedListBox.Items.Clear();
                string dirPath = savesAddressTextBox.Text;
                List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));
                foreach (string folder in dirs)
                {
                    savesCheckedListBox.Items.Add(folder.Substring(folder.LastIndexOf("\\") + 1));
                }
                //加载自动备份设置
                backupAddressTextBox.Text = Properties.Settings.Default.BackupAddress;
                automaticBackupCheckBox.Checked = Properties.Settings.Default.AutomaticBackup;
                backupByTimeRadioButton.Checked = Properties.Settings.Default.AutomaticBackupByTime;
                backupIfChangedRadioButton.Checked = Properties.Settings.Default.AutomaticBackupIfChanged;
                backupWhenStartRadioButton.Checked = !Properties.Settings.Default.AutomaticBackupByTime;
                alwaysBackupRadioButton.Checked = !Properties.Settings.Default.AutomaticBackupIfChanged;
                backupTimeNumericUpDown.Value = Properties.Settings.Default.AutomaticBackupTime / 60000;
                //加载开机自动启动设置
                autoStartCheckBox.Checked = Convert.ToString(Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", Application.ProductName, "")) != "";
                //加载自动删除备份设置
                automaticallyRemoveBackupCheckBox.Checked = Properties.Settings.Default.AutomaticallyRemoveBackup;
                maxBackupFilesNumberradiobutton.Checked = Properties.Settings.Default.AutomaticallyRemoveBackupByFilesNumber;
                maxBackupFileSizeRadioButton.Checked = !Properties.Settings.Default.AutomaticallyRemoveBackupByFilesNumber;
                maxFilesNumberNumericUpDown.Value = Properties.Settings.Default.MaxBackupFilesNumber;
                maxFileSizeNumericUpDown.Value = Properties.Settings.Default.MaxBackupFileSize;
                //加载压缩等级
                zipLevelTrackBar.Value = Properties.Settings.Default.ZipLevel;
                //加载是否显示备份动画
                showBackupIcoCheckBox.Checked = Properties.Settings.Default.ShowBackupIco;
                //调整控件可用性-自动备份设置
                backupTimeNumericUpDown.Enabled = backupByTimeRadioButton.Checked && automaticBackupCheckBox.Checked;
                backupByTimeRadioButton.Enabled = automaticBackupCheckBox.Checked;
                backupWhenStartRadioButton.Enabled = automaticBackupCheckBox.Checked;
                backupIfChangedRadioButton.Enabled = automaticBackupCheckBox.Checked;
                alwaysBackupRadioButton.Enabled = automaticBackupCheckBox.Checked;
                //调整控件可用性-自动删除备份设置
                maxFilesNumberNumericUpDown.Enabled = maxBackupFilesNumberradiobutton.Checked && automaticallyRemoveBackupCheckBox.Checked;
                maxFileSizeNumericUpDown.Enabled = maxBackupFileSizeRadioButton.Checked && automaticallyRemoveBackupCheckBox.Checked;
                maxBackupFilesNumberradiobutton.Enabled = automaticallyRemoveBackupCheckBox.Checked;
                maxBackupFileSizeRadioButton.Enabled = automaticallyRemoveBackupCheckBox.Checked;
                //加载前景色、背景色
                UpdateColor();
                //加载游戏地址
                gameAddressTextBox.Text = Properties.Settings.Default.GameAddress;
            }
            catch (Exception ex)
            {
                HandlingErrors.Record(ex);
            }
        }

        private void showAllSavesLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (showAllSavesLinkLabel.Text == "显示全部存档")
            {
                showAllSavesLinkLabel.Text = "显示要备份的存档";
            }
            else
            {
                showAllSavesLinkLabel.Text = "显示全部存档";
            }
            savesListBox.Visible = !savesListBox.Visible;
            savesCheckedListBox.Visible = !savesCheckedListBox.Visible;
        }

        private void automaticBackupCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            backupByTimeRadioButton.Enabled = automaticBackupCheckBox.Checked;
            backupTimeNumericUpDown.Enabled = automaticBackupCheckBox.Checked;
            backupWhenStartRadioButton.Enabled = automaticBackupCheckBox.Checked;
            backupIfChangedRadioButton.Enabled = automaticBackupCheckBox.Checked;
            alwaysBackupRadioButton.Enabled = automaticBackupCheckBox.Checked;
            Properties.Settings.Default.AutomaticBackup = automaticBackupCheckBox.Checked;
            Properties.Settings.Default.Save();
            //使设置生效
            Main.自动备份AToolStripMenuItem.Checked = Properties.Settings.Default.AutomaticBackup;
            Main.automaticBackupTimer.Enabled = backupByTimeRadioButton.Checked && automaticBackupCheckBox.Checked;
        }

        private void AutomaticallyRemoveBackupCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            maxBackupFilesNumberradiobutton.Enabled = automaticallyRemoveBackupCheckBox.Checked;
            maxFilesNumberNumericUpDown.Enabled = automaticallyRemoveBackupCheckBox.Checked;
            maxBackupFileSizeRadioButton.Enabled = automaticallyRemoveBackupCheckBox.Checked;
            maxFileSizeNumericUpDown.Enabled = automaticallyRemoveBackupCheckBox.Checked;
            Properties.Settings.Default.AutomaticallyRemoveBackup = automaticallyRemoveBackupCheckBox.Checked;
            Properties.Settings.Default.Save();
        }

        private void backupByTimeRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            backupTimeNumericUpDown.Enabled = backupByTimeRadioButton.Checked;
            Properties.Settings.Default.AutomaticBackupByTime = backupByTimeRadioButton.Checked;
            Properties.Settings.Default.Save();
            Main.automaticBackupTimer.Enabled = backupByTimeRadioButton.Checked && automaticBackupCheckBox.Checked;
        }

        private void MaxBackupFilesNumberradiobutton_CheckedChanged(object sender, EventArgs e)
        {
            maxFilesNumberNumericUpDown.Enabled = maxBackupFilesNumberradiobutton.Checked;
            Properties.Settings.Default.AutomaticallyRemoveBackupByFilesNumber = maxBackupFilesNumberradiobutton.Checked;
            Properties.Settings.Default.Save();
        }

        private void maxBackupFileSizeRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            maxFileSizeNumericUpDown.Enabled = maxBackupFileSizeRadioButton.Checked;
            Properties.Settings.Default.AutomaticallyRemoveBackupByFilesNumber = !maxBackupFileSizeRadioButton.Checked;
            Properties.Settings.Default.Save();
        }

        private void savesBrowseLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (savesFolderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                savesAddressTextBox.Text = savesFolderBrowserDialog.SelectedPath;
            }
        }

        private void savesAddressTextBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (savesAddressTextBox.Text.ToLower().Contains("saves"))
                {
                    //获取所有目录名
                    savesCheckedListBox.Items.Clear();
                    string dirPath = savesAddressTextBox.Text;
                    List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));
                    foreach (string folder in dirs)
                    {
                        savesCheckedListBox.Items.Add(folder.Substring(folder.LastIndexOf("\\") + 1));
                    }
                    if (savesCheckedListBox.Items.Count == 0)
                    {
                        savesCheckedListBox.Items.Clear();
                        savesCheckedListBox.Items.Add("未找到存档。");
                    }
                }
                else
                {
                    savesCheckedListBox.Items.Clear();
                    savesCheckedListBox.Items.Add("您指定的不是存档文件夹，请重试。");
                }
            }
            catch (Exception)
            {
                savesCheckedListBox.Items.Clear();
                savesCheckedListBox.Items.Add("出现错误，请检查目录是否存在。");
            }
        }

        private void savesAddressTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            showAllSavesLinkLabel.Text = "已显示全部存档";
            showAllSavesLinkLabel.Enabled = false;
            savesListBox.Visible = false;
            savesCheckedListBox.Visible = true;
        }

        private void backupAddressTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            saveButton.Enabled = true;
        }

        private void backupBrowseLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (backupFolderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                backupAddressTextBox.Text = backupFolderBrowserDialog.SelectedPath;
                saveButton.Enabled = true;
            }
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            //保存全部设置
            //检查有无异常选择项
            if (savesListBox.Items.Count == 0)
            {
                MessageBox.Show("请选择您要备份的游戏存档。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (savesListBox.Items.Contains("您指定的不是存档文件夹，请重试。"))
            {
                MessageBox.Show("您指定的不是存档文件夹，请重试。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (savesListBox.Items.Contains("出现错误，请检查目录是否存在。"))
            {
                MessageBox.Show("出现错误，请检查目录是否存在。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (savesListBox.Items.Contains("未找到存档。"))
            {
                MessageBox.Show("未找到存档。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                try
                {
                    //禁用所有按钮
                    saveButton.Enabled = false;
                    saveButton.Text = "请稍后(0%)";
                    showAllSavesLinkLabel.Enabled = false;
                    backupBrowseLinkLabel.Enabled = false;
                    savesBrowseLinkLabel.Enabled = false;
                    //写入SaveAddress
                    string savesAddress = savesAddressTextBox.Text;
                    if (savesAddress.EndsWith("\\"))
                    {
                        Properties.Settings.Default.SaveAddress = savesAddressTextBox.Text;
                    }
                    else
                    {
                        Properties.Settings.Default.SaveAddress = savesAddressTextBox.Text + "\\";
                    }
                    //写入BackupDirectoryAddress
                    Properties.Settings.Default.BackupDirectoryAddress.Clear();
                    foreach (object item in savesListBox.Items)
                    {
                        string backupDirectoryAddress;
                        if (savesAddress.EndsWith("\\"))
                        {
                            backupDirectoryAddress = savesAddress + item;
                        }
                        else
                        {
                            backupDirectoryAddress = savesAddress + "\\" + item;
                        }
                        Properties.Settings.Default.BackupDirectoryAddress.Add(backupDirectoryAddress);
                        backupDirectoryAddress = null;
                    }
                    //记录备份地址
                    if (backupAddressTextBox.Text.EndsWith("BackupSaves\\"))
                    {
                        Properties.Settings.Default.BackupAddress = backupAddressTextBox.Text;
                    }
                    else if (backupAddressTextBox.Text.EndsWith("BackupSaves"))
                    {
                        Properties.Settings.Default.BackupAddress = backupAddressTextBox.Text + "\\";
                    }
                    else if (backupAddressTextBox.Text.EndsWith("\\"))
                    {
                        Properties.Settings.Default.BackupAddress = backupAddressTextBox.Text + "BackupSaves\\";
                    }
                    else
                    {
                        Properties.Settings.Default.BackupAddress = backupAddressTextBox.Text + "\\BackupSaves\\";
                    }
                    Directory.CreateDirectory(Properties.Settings.Default.BackupAddress);
                    //保存设置
                    Properties.Settings.Default.Save();
                    backgroundWorker.RunWorkerAsync();
                }
                catch (Exception ex)
                {
                    HandlingErrors.ErrorMessage(ex, "请再试一次。");
                    HandlingErrors.Record(ex);
                }
            }
        }

        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                double count = 0;
                double all = Properties.Settings.Default.BackupDirectoryAddress.Count;
                Properties.Settings.Default.MD5.Clear();
                foreach (string directoryName in Properties.Settings.Default.BackupDirectoryAddress)
                {
                    DirectoryInfo directory = new DirectoryInfo(directoryName);
                    //遍历文件
                    foreach (FileInfo files in directory.GetFiles("*", SearchOption.AllDirectories))
                    {
                        //计算MD5
                        string fileName = files.FullName;
                        string md5 = "";
                        byte[] hashValue;
                        FileStream fileStream = null;
                        System.Security.Cryptography.MD5CryptoServiceProvider md5CSP = new System.Security.Cryptography.MD5CryptoServiceProvider();
                        fileStream = new FileStream(fileName.Replace("\"", ""), System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                        hashValue = md5CSP.ComputeHash(fileStream);
                        fileStream.Close();
                        md5 = BitConverter.ToString(hashValue);
                        md5 = md5.Replace("-", "");
                        Properties.Settings.Default.MD5.Add("{" + fileName + "}" + md5);
                    }
                    count++;
                    backgroundWorker.ReportProgress(Convert.ToInt32(count / all * 100));
                }
                Properties.Settings.Default.Save();
            }
            catch (Exception ex)
            {
                HandlingErrors.ErrorMessage(ex, "请再试一次。");
                HandlingErrors.Record(ex);
            }
        }

        private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            saveButton.Text = "请稍后(" + Convert.ToString(e.ProgressPercentage) + "%)";
        }

        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            saveButton.Enabled = false;
            saveButton.Text = "保存(&S)";
            showAllSavesLinkLabel.Enabled = true;
            showAllSavesLinkLabel.Text = "显示要备份的存档";
            backupBrowseLinkLabel.Enabled = true;
            savesBrowseLinkLabel.Enabled = true;
        }

        private void savesCheckedListBox_MouseUp(object sender, MouseEventArgs e)
        {
            savesListBox.Items.Clear();
            foreach (object item in savesCheckedListBox.CheckedItems)
            {
                savesListBox.Items.Add(item);
            }
            saveButton.Enabled = true;
        }

        private void autoStartCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            //开机启动
            try
            {
                if (autoStartCheckBox.Checked)
                {
                    Microsoft.Win32.Registry.SetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", Application.ProductName, Application.ExecutablePath);
                }
                else
                {
                    Microsoft.Win32.Registry.SetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", Application.ProductName, "");
                }
            }
            catch (Exception ex)
            {
                HandlingErrors.ErrorMessage(ex, "请再试一次。");
                HandlingErrors.Record(ex);
            }
        }

        private void backupTimeNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.AutomaticBackupTime = Convert.ToInt32(backupTimeNumericUpDown.Value * 60000);
            Properties.Settings.Default.Save();
            //使设置生效
            Main.automaticBackupTimer.Interval = Convert.ToInt32(backupTimeNumericUpDown.Value * 60000);
        }

        private void backupWhenStartRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.AutomaticBackupByTime = !backupWhenStartRadioButton.Checked;
            Properties.Settings.Default.Save();
            //使设置生效
            Main.automaticBackupTimer.Enabled = backupByTimeRadioButton.Checked && automaticBackupCheckBox.Checked;
        }

        private void backupIfChangedRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.AutomaticBackupIfChanged = backupIfChangedRadioButton.Checked;
            Properties.Settings.Default.Save();
        }

        private void alwaysBackupRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.AutomaticBackupIfChanged = !alwaysBackupRadioButton.Checked;
            Properties.Settings.Default.Save();
        }

        private void maxFilesNumberNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.MaxBackupFilesNumber = Convert.ToInt32(maxFilesNumberNumericUpDown.Value);
            Properties.Settings.Default.Save();
        }

        private void maxFileSizeNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.MaxBackupFileSize = Convert.ToInt32(maxFileSizeNumericUpDown.Value);
            Properties.Settings.Default.Save();
        }

        private void zipLevelTrackBar_Scroll(object sender, EventArgs e)
        {
            Properties.Settings.Default.ZipLevel = zipLevelTrackBar.Value;
            Properties.Settings.Default.Save();
        }

        private void showBackupIcoCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.ShowBackupIco = showBackupIcoCheckBox.Checked;
            Properties.Settings.Default.Save();
        }

        private void foreColorWhiteLabel_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.ForeColor = Color.White;
            Properties.Settings.Default.Save();
            UpdateColor();
        }

        private void foreColorBlackLabel_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.ForeColor = Color.Black;
            Properties.Settings.Default.Save();
            UpdateColor();
        }

        private void backColorDodgerBlueLabel_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.BackColor = Color.DodgerBlue;
            Properties.Settings.Default.ForeColor = Color.White;
            Properties.Settings.Default.Save();
            UpdateColor();
        }

        private void backColorTomatoLabel_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.BackColor = Color.Tomato;
            Properties.Settings.Default.ForeColor = Color.White;
            Properties.Settings.Default.Save();
            UpdateColor();
        }

        private void backColorSpringGreenLabel_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.BackColor = Color.SpringGreen;
            Properties.Settings.Default.ForeColor = Color.Black;
            Properties.Settings.Default.Save();
            UpdateColor();
        }

        private void backColorBlueVioletLabel_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.BackColor = Color.BlueViolet;
            Properties.Settings.Default.ForeColor = Color.White;
            Properties.Settings.Default.Save();
            UpdateColor();
        }

        private void backColorTurquoiseLabel_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.BackColor = Color.Turquoise;
            Properties.Settings.Default.ForeColor = Color.Black;
            Properties.Settings.Default.Save();
            UpdateColor();
        }

        private void backColorOtherLabel_Click(object sender, EventArgs e)
        {
            if (colorDialog.ShowDialog() == DialogResult.OK)
            {
                Properties.Settings.Default.BackColor = colorDialog.Color;
                if (colorDialog.Color.R + colorDialog.Color.G + colorDialog.Color.B > 255 * 3 / 2)
                {
                    Properties.Settings.Default.ForeColor = Color.Black;
                }
                else
                {
                    Properties.Settings.Default.ForeColor = Color.White;
                }
                Properties.Settings.Default.Save();
                UpdateColor();
            }
        }

        private void gameAddressTextBox_TextChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.GameAddress = gameAddressTextBox.Text;
            Properties.Settings.Default.Save();
        }

        private void gameAddressBrowseLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (openGameDialog.ShowDialog() == DialogResult.OK)
            {
                gameAddressTextBox.Text = openGameDialog.FileName;
                Properties.Settings.Default.GameAddress = gameAddressTextBox.Text;
                Properties.Settings.Default.Save();
            }
        }
    }
}
